package cn.ichiva.service;

import org.springframework.data.redis.core.*;

import java.util.Collection;
import java.util.Date;
import java.util.Set;
import java.util.concurrent.TimeUnit;

public class KeyService {
    private final RedisTemplate<String,String> redis;

    public KeyService(RedisTemplate<String, String> redis) {
        this.redis = redis;
    }
    
    public Boolean hasKey(String key) {
        return redis.hasKey(key);
    }

    
    public Long countExistingKeys(Collection<String> keys) {
        return redis.countExistingKeys(keys);
    }

    
    public Boolean delete(String key) {
        return redis.delete(key);
    }

    
    public Long deletes(Collection<String> keys) {
        return redis.delete(keys);
    }

    
    public String type(String key) {
        return redis.type(key).code();
    }

    
    public Set<String> keys(String pattern) {
        return redis.keys(pattern);
    }

    
    public String randomKey() {
        return redis.randomKey();
    }

    
    public void rename(String oldKey, String newKey) {
        redis.rename(oldKey, newKey);
    }

    
    public Boolean renameIfAbsent(String oldKey, String newKey) {
        return redis.renameIfAbsent(oldKey, newKey);
    }

    
    public Boolean expire(String key, long timeout) {
        return redis.expire(key, timeout, TimeUnit.MILLISECONDS);
    }

    
    public Boolean expireAt(String key, long date) {
        return redis.expireAt(key,new Date(date));
    }

    
    public Boolean persist(String key) {
        return redis.persist(key);
    }

    
    public Boolean move(String key, int dbIndex) {
        return redis.move(key, dbIndex);
    }

    
    public Long getExpire(String key) {
        return redis.getExpire(key);
    }
}
